﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UIBase : MonoBase
{

    /// <summary>
    ///  自身关心的消息集合
    /// </summary>
    List<int> mList = new List<int>();

    /// <summary>
    ///  绑定一个或多个消息
    /// </summary>
    /// <param name="eventCodes"></param>
    protected void Bind(params int[] eventCodes)
    {
        mList.AddRange(eventCodes);
        UIManager.Instance.AddMulti(mList.ToArray(), this);
    }

    /// <summary>
    ///   解除绑定的消息
    /// </summary>
    protected void UnBind()
    {
        UIManager.Instance.RemoveMulti(mList.ToArray(), this);
        mList.Clear();
    }

    /// <summary>
    ///  游戏物体销毁，自动移除绑定
    /// </summary>
    public virtual void OnDestroy()
    {
        if (mList != null)
        {
            UnBind();
        }

    }

    /// <summary>
    ///    发送消息
    /// </summary>
    /// <param name="areaCode"></param>
    /// <param name="eventCode"></param>
    /// <param name="message"></param>
    public void Dispatch(int areaCode, int eventCode, object message)
    {
        MsgCenter.Instance.Dispatch(areaCode, eventCode, message);
    }

}
